<?php

# $Id$
# Copyright 2010, Rasmus Schultz <http://mindplay.dk>

header('Content-type: text/plain');

?>
Fast URL Resolver
=================

Copyright 2010, Rasmus Schultz <http://mindplay.dk>

For more information, please visit the google code page:

http://code.google.com/p/fast-url-resolver/

This example script will load (and compile, as needed) a sample
resolver class (TestResolver) - and have it resolve a list of
sample URIs, and print out the return value for each.


Input File
----------

The input configuration file, which compiles into the TestResolver
class, is displayed below.

Examine the generated "TestResolver.php" file, to understand 
how the resolver works internally, if you'd like.

<?php readfile('example.fur.txt'); ?>


Examples of URI resolution
--------------------------

The following are examples of resolving URIs with the TestResolver.

Note that the last URIs in the test below are designed to fail,
and therefore should return false.

<?

// load the FUR library:
require '../lib/FUR.php';

unlink('TestResolver.php');

// load (and compile, if needed) an example resolver:
FUR::load('example.fur.txt', 'TestResolver.php', 'TestResolver');

// create an instance:
$test = new TestResolver();

// define some URIs for testing:
$uris = array(
  'test/stuff.html' => 'POST',
  'buildings' => 'GET',
  'building/north' => 'GET',
  'building/east/department/ornithology' => 'GET',
  'building/west/department/history/person/arthur' => 'GET',
  'admin/article' => 'GET',
  'admin/article/123' => 'GET',
  'admin/article/123/comment' => 'GET',
  'admin/article/123/comment/456' => 'GET',
  // the following are invalid URIs - they should fail and return false:
  'admin/article/234' => 'AJAX',  # invalid method
  'fail' => 'GET',                # undefined URI
  'building/fail/' => 'GET',      # extra trailing slash
  'building/north/fail' => 'GET', # undefined nested resource
  'test/fail' => 'GET',           # undefined nested URI
);

// run the tests:
foreach ($uris as $uri => $method)
{
  echo "Resolving: {$uri} ~ method: {$method}\n";
  var_dump($test->resolve($uri,$method));
  echo "\n";
}

?>

Examples of URI creation
------------------------

The following are examples of generating URIs with the TestResolver.

<?php

$examples = array(
  '$test->test_uri(\'example\', \'png\');',
  '$test->building_uri(\'east\');',
  '$test->admin_comment_uri(123, 456);',
);

foreach ($examples as $code)
{
  echo $code . "\n  => ";
  echo eval('return '.$code) . "\n\n";
}
